﻿var AttachActionsOnReady = new Array();


function attachActionButton(className) {
    var parameters = new Object();
    for (var xa = 1; xa < arguments.length; xa++) {
        parameters[arguments[xa++]] = arguments[xa];
    }
    var attachInfo = new Object();
    attachInfo.ClassName = className;
    attachInfo.Parameters = parameters;
    AttachActionsOnReady.push(attachInfo);
}

function attachActionButtonReady(className, parameters) {
    if ($('.' + className).data('params')) return;
    $('.' + className).data('params', parameters).css('cursor', 'pointer').click(actionButtonClick);
}

function actionButtonClick() {
    var parameters = $(this).data('params');
    var domForm = $('form:eq(0)');
    if (parameters && domForm.length > 0) {
        for (var key in parameters) {
            if (!$('input[name= ' + key + ' ]').is('*')) {
                $('<input />',
                        {
                            type: 'hidden',
                            name: key
                        }).appendTo(domForm);
            }
            $('input[name= ' + key + ' ]').val(parameters[key]);
        }
        domForm.submit();
    }
}


$(document).ready(function () {
    for (var xaa = 0; xaa < AttachActionsOnReady.length; xaa++) {
        attachActionButtonReady(AttachActionsOnReady[xaa].ClassName, AttachActionsOnReady[xaa].Parameters);
    }
});
